﻿using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace PesticideManage.API.Extensions;

public static class ClaimsPrincipalExtensions
{
    public static int GetId(this ClaimsPrincipal claimsPrincipal)
    {
        if (claimsPrincipal is null)
        {
            return 0;
        }
        string idStr = claimsPrincipal.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new NullReferenceException(ClaimTypes.NameIdentifier);
        return int.Parse(idStr);
    }
}
